package com.lanou.tipsy.fragment.person;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lanou.tipsy.R;
import com.lanou.tipsy.base.BaseFragment;



/**
 * Created by Zouweiwei on 15/10/20.
 * <p/>
 * <p/>
 * 个人信息页面
 */
public class MineFragment extends BaseFragment implements View.OnClickListener {
    private Context mContext;
    private FrameLayout myMusic;  //我的音乐选项
    private LinearLayout myCollection, mine_login;//我的收藏行布局
    private ImageView mine_icon;  //头像
    private TextView mine_name; //昵称


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fr_personal, null);
        return view;
    }

    /**
     * 复写onAttach方法
     *
     * @param context
     */
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.mContext = context;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView(getView());
    }

    //初始化控件->添加监听
    private void initView(View view) {
        myMusic = (FrameLayout) view.findViewById(R.id.li_myMusic);
        myMusic.setOnClickListener(this);
        myCollection = (LinearLayout) view.findViewById(R.id.myCollection);
        myCollection.setOnClickListener(this);
        mine_icon = (ImageView) view.findViewById(R.id.mine_icon);
        mine_name = (TextView) view.findViewById(R.id.mine_name);
        mine_login = (LinearLayout) view.findViewById(R.id.mine_login);
        mine_login.setOnClickListener(this);
    }

    Fragment myMusicFragment = new MyMusicFragment();

    @Override
    public void onClick(View v) {
        FragmentManager manager = getActivity().getSupportFragmentManager();
        switch (v.getId()) {
            //点击跳转到本地歌曲列表
            case R.id.li_myMusic:
                FragmentTransaction transaction = manager.beginTransaction();
                transaction.add(R.id.fl_main, myMusicFragment);
                transaction.addToBackStack(null);
                transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                transaction.commit();
                break;
            //点击跳转到歌曲收藏界面
            case R.id.myCollection:
                FragmentTransaction tra = manager.beginTransaction();
                tra.replace(R.id.fl_main, new MyCollectFragment());
                Log.i("test", "MineFragment->跳转到收藏界面");
                tra.addToBackStack(null);
                tra.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                tra.commit();
                break;
            //个人头像
            case R.id.mine_login:

                break;
        }
    }


    @Override
    public void onResume() {
        super.onResume();
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
